#include "Render.h"
#include <cstdlib>
#include <time.h>

Render::Render(){
    tracer = new Tracer();
}

Render::~Render(){
    delete tracer;
}

float* Render::renderPixel(int x_pos, int y_pos){

    //Skapa ray från scene->getEyepos genom alla pixlar

    float *retPixel;
    float pixel[4];
    pixel[0] = 0.0f;
    pixel[1] = 0.0f;
    pixel[2] = 0.0f;
    pixel[3] = 1.0f;

    Vector3<float> tracedPixel;
    float xOffs = (float)rand()/RAND_MAX -1.0;
    float yOffs = (float)rand()/RAND_MAX -1.0;
    Vector3<float> pointOnViewPlane = Vector3<float>(x_pos+xOffs, y_pos+yOffs, 0.0);
    Vector3<float> dir = pointOnViewPlane - tracer->scene->eyePos;
    Ray r(tracer->scene->eyePos, dir);

    tracedPixel = tracer->traceRay(r, 1.0, 0);

    pixel[0] = tracedPixel[0];
    pixel[1] = tracedPixel[1];
    pixel[2] = tracedPixel[2];

    retPixel = pixel;

    return retPixel;

    }
